package com.example.administrator.testproject.downM3U8;

import com.example.administrator.testproject.download.DownState;

import java.util.Collection;

/**
 * Created by shengfh on 2018/2/1.
 */

public class DownUtil {
    /**
     * 判断当前下载状态
     *
     * @param downInfos
     */
    public static DownState getVideoStatus(Collection<ItemM3U8Ts> downInfos) {
        if (downInfos == null) return DownState.START;
        DownState tempState = DownState.FINISH;
        int startCount = 0;
        for (ItemM3U8Ts info : downInfos) {
            //只要有一个下载中，就是下载中
            if (info.getState() == DownState.DOWN) {
                return DownState.DOWN;
            }
            //全部暂停
            if (info.getState() == DownState.PAUSE) {
                tempState = DownState.PAUSE;
                continue;
            }
            //有暂停，有未下载
            if (info.getState() == DownState.START) {
                tempState = DownState.START;
                startCount++;
            }
        }
        if (tempState == DownState.START) {
            if (startCount == downInfos.size()) {
                tempState=DownState.START;
            } else {
                tempState=DownState.PAUSE;
            }
        }

        return tempState;
    }
}
